<template>
  <el-container>
    <el-header class="header">
      <div class="" >
        企业姓名：
        <el-input class="com-input"
          placeholder="请输入企业姓名"
          v-model="name">
        </el-input>
        企业类型：
        <el-select v-model="type" placeholder="全部">
          <el-option
            v-for="item in typeList"
            :key="item.id"
            :label="item.dValue"
            :value="item.dKey">
          </el-option>
        </el-select>
        <el-button type="primary" icon="el-icon-search" class="btn" @click="search">搜索</el-button>
        <el-button type="primary" @click="addCom" class="btn" plain>新增企业</el-button>
      </div>
    </el-header>
    <el-main>
      <el-table :data="comInfoList">
        <el-table-column prop="id" align="center" label="ID">
        </el-table-column>
        <el-table-column prop="name" align="center" label="企业名字">
        </el-table-column>
        <el-table-column prop="address" align="center" label="企业地址">
        </el-table-column>
        <el-table-column prop="propertyValue" align="center" label="公司性质">
        </el-table-column>
        <el-table-column prop="typeValue" align="center" label="企业类型">
        </el-table-column>
        <el-table-column prop="ipoValue" align="center" label="是否上市">
        </el-table-column>
        <el-table-column prop="mobile" align="center" label="联系电话" width="110">
        </el-table-column>
        <el-table-column prop="createTimeValue" align="center" label="入驻时间">
        </el-table-column>
        <el-table-column label="操作" align="center" width='220'>
          <template slot-scope="scope">
            <el-button @click="editCom(scope.row)" type="text" size="small">编辑</el-button>
            <el-button type="text" size="small" @click="toGoodsList(scope.row)">商品管理</el-button>
            <el-button type="text" size="small" @click="toservesList(scope.row)">服务单管理</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="demonstration-box">
        <!-- <span class="demonstration">显示总数</span> -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageParams.size"
          layout="total, prev, pager, next"
          :total="pageParams.totalCount"
        ></el-pagination>
      </div>
    </el-main>
  </el-container>
</template>
<script>
const queryString = require('querystring')
import page from 'data/page'
import {typeList} from 'data/listBody'
export default {
  name: 'comList',
  mixins: [page],
  data() {
    return {
      comInfoList: [],
      name: '',
      type: '',
      currentPage: 1,
      pageShow: false,
      typeList
    }
  },
  created() {
    this.search()
  },
  methods: {
    addCom() {
      this.$router.push('addOrEditCom?type=add')
    },
    toservesList(item) {
      this.$router.push('servesList?id=' + item.id + '&companyName=' + item.name)
    },
    editCom(item) {
      this.$router.push('addOrEditCom?type=edit&id=' + item.id)
    },
    toGoodsList(item) {
      this.$router.push('goodsList?companyName=' + item.name + '&id=' + item.id)
    },
    search() {
      const params = {
        name: this.name,
        type: this.type,
        page: this.currentPage - 1,
        size: 20
      }
    this.axios.get('/company?' + queryString.stringify(params)).then((res) => {
        const code = Number(res.data.code)
        if (code === 200) {
          this.comInfoList = res.data.data.list
          this.comInfoList.forEach((comInfo, index) => {
            this.comInfoList[index].ipoValue = comInfo.ipo ? '是' : '否'
            this.comInfoList[index].createTimeValue = this.timeFormater(comInfo.createTime).format('YYYY-MM-DD')
          })
          this.setPage(res.data.data)
        } else {
          this.$message(this.mes.busy)
        }
      }).catch((err) => {
        console.log(err)
        this.$message(this.mes.busy)
      })
    }
  }
}
</script>
<style lang="less" scoped>
  .header {
    text-align: left;
    border-bottom: 1px solid #eee
  }
  .com-input {
    width: 210px;
    margin-right: 20px
  }
  .btn{
    margin-left: 20px;
  }
</style>

